package com.epcs.subGNuevosNegocios.eci.struts.action.tree;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.epcs.subGNuevosNegocios.eci.dao.tree.TreeDAOImplement;
import com.epcs.subGNuevosNegocios.eci.struts.action.base.BaseAction;
import com.epcs.subGNuevosNegocios.eci.to.EmpleadoTO;
import com.epcs.subGNuevosNegocios.eci.to.HijounidadTO;

public class TreeAction extends BaseAction {
	
	public ActionForward showChilds(ActionMapping mapping,ActionForm form,
            HttpServletRequest request,HttpServletResponse response) 
    throws Exception
    {
		DynaActionForm actionForm = (DynaActionForm) form;
		String idPadre = (String) actionForm.get("idPadre");
		TreeDAOImplement tdi = new TreeDAOImplement();
		List<HijounidadTO> lstHijos = tdi.getHijosUnidad(idPadre);
		request.setAttribute("lstHijos", lstHijos);
	return mapping.findForward("ajaxTree");	
    }
	
	public ActionForward showEmployees(ActionMapping mapping,ActionForm form,
            HttpServletRequest request,HttpServletResponse response) 
    throws Exception{

		DynaActionForm actionForm = (DynaActionForm) form;
		String idArea = (String) actionForm.get("idArea");
		Integer nivel = Integer.parseInt(actionForm.get("nivel").toString());
		
		TreeDAOImplement tdi = new TreeDAOImplement();
		List<EmpleadoTO> lstEmpleado = tdi.getEmpleadosUnidad(idArea);
		request.setAttribute("lstEmpleado", lstEmpleado);
		
		if(nivel==3)
			return mapping.findForward("ajaxEmployees2");
		else
			return mapping.findForward("ajaxEmployees");
		
	}
}
